/**══════════════════════════════════╗
*作    者：songbaobao                                                  ║
*职    业：我以我血荐轩辕                                              ║
*CSND地址：https://blog.csdn.net/weixin_43949535                       ║
**GitHub ：https://github.com/TsinghuaLucky912/My_own_C-_study_and_blog║
**GitEE  ：https://gitee.com/lucky912_admin/code-up_-pat               ║
*═══════════════════════════════════╣
*创建时间：2021年08月25日 23:50:18                                     
*功能描述：                                                            
*                                                                      
*                                                                      
*═══════════════════════════════════╣
*结束时间:                                                           
*═══════════════════════════════════╝
//                .-~~~~~~~~~-._       _.-~~~~~~~~~-.
//            __.'              ~.   .~              `.__
//          .'//              西南\./联大               \\`.
//        .'//                     |                     \\`.
//      .'// .-~"""""""~~~~-._     |     _,-~~~~"""""""~-. \\`.
//    .'//.-"                 `-.  |  .-'                 "-.\\`.
//  .'//______.============-..   \ | /   ..-============.______\\`.
//.'______________________________\|/______________________________`.
*/

#include "main.h"

void myvecPrint(vector<vector<int>>& mymap)
{
	for (vector<vector<int>>::iterator it1 = mymap.begin(); it1 != mymap.end(); ++it1)
	{
		for (vector<int>::iterator it2 = it1->begin(); it2 != it1->end(); ++it2)
		{
			cout << *it2 << "   ";
		}
		cout << endl;
	}
	cout << "------------------------------------------------------" << endl;
}

int main()
{
	
	initgraph(WIDOWWIDTH, WIDOWHEIGHT, SHOWCONSOLE); // 调试使用
	// initgraph(WIDOWWIDTH, WIDOWHEIGHT);

#if 0
	srand((unsigned)time(nullptr));

	// 设置背景颜色格式 透明
	setbkmode(TRANSPARENT);
#endif

	// 提供一个 4*4 的二维向量来存储数据
	vector<vector<int>>mymap(GRIDNUM, vector<int>(GRIDNUM, 0));

	srandTwoOrFour(mymap);
	srandTwoOrFour(mymap);

	while (true)
	{
		//myvecPrint(mymap);
		//Sleep(6000);

		gameInit(mymap);
		if (gameTestWinOrContinue(mymap))
		{
			int x = MessageBox(GetForegroundWindow(), "You have successfully reached 2048!", "RESTART OR QUIT", 5);
			
			cout << x << endl;
			if (4 == x) // 重试
			{
				for (vector<vector<int>>::iterator it1 = mymap.begin(); it1 != mymap.end(); ++it1)
				{
					for (vector<int>::iterator it2 = it1->begin(); it2 != it1->end(); ++it2)
					{
						*it2 = 0;
					}
				}

				srandTwoOrFour(mymap);
				srandTwoOrFour(mymap);
			}
			else if (2 == x)
			{
				exit(0);
			}
		}

		if (gameControl(mymap))
		{
			//myvecPrint(mymap); // 调试使用
			srandTwoOrFour(mymap);
		}		
		else
		{

		}
	}
	closegraph();
	return 0;
}
/**
*备用注释：
*
*
*
*/


#if 0
int main()
{
	vector<vector<int>>myvec(4, vector<int>(4, 0));

	int index = 1;
	for (int i = 0; i < 4; ++i)
	{
		for (int j = 0; j < 4; ++j)
		{
			myvec[i][j] = pow(2, index++);
		}
	}
	myvecPrint(myvec);
	
	for (vector<vector<int>>::iterator it1 = myvec.begin(); it1 != myvec.end(); ++it1)
	{
		for (vector<int>::iterator it2 = it1->begin(); it2 != it1->end(); ++it2)
		{
			cout << log2(*it2) << " ";
		}
		cout << endl;
	}
}
#endif
